/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Ultility;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author gxr116020
 */
public class RunAlgorithm {

    String prefix = "F:/Experiments/gzip-all/";
    String end1 = "/100%/HammingResultFile/Rank/Tarantula";
    String end2 = "/100%/HammingResultFile/Rank/Crosstab";
    String end3 = "/100%/HammingResultFile/Rank/Ochiai";
    int numberall = 30;
    int bugsize = 3;
    public static File file;
    public static File[] filename;
    public static readTextlines r;
    String[][] versionsall;
    String[][] faultLocationALL;
    double[][] one_round_matrix;

    public static void main(String[] args) {
        System.out.println("******************Here Run Algorithm*********************");


    }

    void Read_Version_and_Location() {
        versionsall = new String[numberall][bugsize];
        faultLocationALL = new String[numberall][bugsize];
        try {
            Scanner version_scanner = new Scanner(new File("F:/Experiments/bugversion.txt"));
            int count1 = 0;
            while (version_scanner.hasNextLine()) {
                String[] allsub = null;
                String tmp = version_scanner.nextLine();
                ArrayList<String> versionsaver = new ArrayList<String>();
                if (tmp.trim().equals("")) {
                    continue;
                } else {
                    tmp = tmp.trim();
                    allsub = tmp.split("-");
                    for (int i = 0; i < allsub.length; i++) {
                        String a;
                        a = allsub[i];
                        if (!a.equals("v")) {
                            versionsaver.add(a);
                        }
                    }
                    String[] versionSave = new String[versionsaver.size()];
                    for (int i = 0; i < versionsaver.size(); i++) {
                        versionSave[i] = versionsaver.get(i);
                    }
                    versionsall[count1] = versionSave;
                    count1++;
                }
            }
            //buglocation
            Scanner location_scanner = new Scanner(new File("F:/Experiments/buglocation.txt"));
            int count2 = 0;
            while (location_scanner.hasNextLine()) {
                String[] allsub = null;

                String tmp = location_scanner.nextLine();
                ArrayList<String> versionsaver = new ArrayList<String>();
                if (tmp.trim().equals("")) {
                    continue;
                } else {
                    tmp = tmp.trim();
                    allsub = tmp.split("/");
                    for (int i = 0; i < allsub.length; i++) {
                        String a;
                        a = allsub[i];
                        versionsaver.add(a);
                    }

                    String[] versionSave = new String[versionsaver.size()];
                    for (int i = 0; i < versionsaver.size(); i++) {
                        versionSave[i] = versionsaver.get(i);
                    }
                    faultLocationALL[count2] = versionSave;
                    count2++;
                }
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(RunAlgorithm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    void Set_Version_and_Location() {
        String[][] versiontemp = {{"3", "4", "18"}, {"3", "5", "19"}, {"8", "13", "18"}};
        String[][] locationtemp = {{"433", "600", "1389", "536"}, {"433", "600", "1389", "800"}, {"17", "28", "76", "536"}};

        this.versionsall = versiontemp;
        this.faultLocationALL = locationtemp;
    }

    void Read_MATRIX_in_one_version() {
        filename = file.listFiles();
        String f = (filename[0].getAbsolutePath()).toString();
        r = new readTextlines(f);
        one_round_matrix = new double[filename.length][r.getCount()];
        for (int i = 0; i < filename.length; i++) {
            //read one rank file
            String ff = (filename[i].getAbsolutePath()).toString();
            //System.out.println(ff);
            readTextlines rr = new readTextlines(ff);
            String[] data = new String[rr.getCount()];
            data = rr.getData(ff);
            for (int j = 0; j < rr.getCount(); j++) {
                one_round_matrix[i][j] = Double.valueOf(data[j]);
            }
        }
    }
}